var newVue = new Vue({
	el: "body",
	data: {
		username: "",
		phone: "",
		area: "",
		address: "",
		istrue: false //判断是否是无效手机号
	},
	created: function() {
		init();
		_this = this;
		verifyLogin()
	},
	methods: {
		save: function() {
			_this.checkPhone()
			if(_this.username.trim().length > 0 && _this.address.trim().length > 0 && _this.area.trim().length > 0 && _this.istrue == true) {
				addAddress(_this)
				_this.username = ""
				_this.phone = ""
				_this.area = ""
				_this.address = ""
				_this.istrue = false
			} else {
				alert("请完善输入信息")
			}
		},
		checkPhone: function() {
			var phone = _this.phone;
			var reg = /^1[34578]\d{9}$/;
			if(reg.test(phone)) {
				this.istrue = true;
			} else {
				this.istrue = false;
			}
		}
	}
})

function addAddress(a) {
	var Product = AV.Object.extend('Address')
	var product = new Product();
	product.set('username', a.username);
	product.set('phone', a.phone);
	product.set('area', a.area);
	product.set('address', a.address);
	product.set('isDefault', "none");
	product.set('user', currentUser.attributes.username);
	product.save().then(function() {
		alert("保存成功")
	}, function(error) {
		alert("failure")
	});
}

function verifyLogin() {
	currentUser = AV.User.current();
	if(currentUser) {

	} else {
		location.href = "../login/login.html?RetUrl=" + getPageUrl()
	}
}